// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package conf

const (
	DefaultFileLoggerName      = "2006-01-02.log"
	DefaultFileLoggerPath      = "./logs"
	DefaultFileLoggerSeparator = "2006-01"
)

// FileAdapterConfig
// is a component for file.
//
//   - /var/logs/sketch/2024-01/2024-01-10.log
type FileAdapterConfig struct {
	// Json
	// converts as json string or not.
	//
	//   Default: false
	Json bool `yaml:"json"`

	// FileName
	// saved log file name.
	//
	//   Example: 2024-01-10.log
	FileName string `yaml:"name"`

	// FilePath
	// log file saved path.
	//
	//   Default: ./logs
	FilePath string `yaml:"path"`

	// FileSeparator
	// log files separated by month.
	//
	//   Default: 2006-01 (Month)
	FileSeparator string `yaml:"separator"`
}

// +---------------------------------------------------------------------------+
// | Access methods                                                            |
// +---------------------------------------------------------------------------+

func (o *FileAdapterConfig) init() {
	if o.FileName == "" {
		o.FileName = DefaultFileLoggerName
	}
	if o.FilePath == "" {
		o.FilePath = DefaultFileLoggerPath
	}
	if o.FileSeparator == "" {
		o.FileSeparator = DefaultFileLoggerSeparator
	}
}
